package model;

import java.util.ArrayList;
import java.util.List;

public class Grid {

	private static int BOARD_WIDTH = 10;
	private static int BOARD_HEIGHT = 22;

	private static String BOARD_DEFN = "VVVVSSVVVV" +
									   "VVVVSSVVVV" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE" +
									   "EEEEEEEEEE";

	List<List<GridLocation>> grid;
	
	Shape shape;

	public Grid() {
		initGrid();
	}

	public void initGrid() {
		grid = new ArrayList<List<GridLocation>>(BOARD_HEIGHT);
		for (int i = 0; i < BOARD_HEIGHT; i++) {
			grid.add(new ArrayList<GridLocation>(BOARD_WIDTH));
		}
		
		for (int i = 0; i < BOARD_DEFN.length(); i++) {
			char type = BOARD_DEFN.charAt(i);
			
			int x = i % BOARD_WIDTH;
			int y = i / BOARD_WIDTH;
			
			if (type == 'S') {
				Shape s = new Shape(this, x, y);
				grid.get(y).add(new GridLocation('D', s));
			}
		}
		
	}
	
	public void updateGame() {
		shape.move();
	}

	public void clearLine() {

	}

	public void moveShape() {

	}

	public void newShape() {

	}

	public void endGame() {
		if (isGameOver() == true) {
		}
	}

	public boolean isGameOver() {
		return false;
	}
	
	public int getBoardWidth() {
		return BOARD_WIDTH;
	}
	
	public int getBoardHeight() {
		return BOARD_HEIGHT;
	}
	
	public GridLocation getLocation(int x, int y) {
		return grid.get(y).get(x);
	}
	
	public List<List<GridLocation>> getGridRows() {
		return grid;
	}

}